﻿using MediatR;
using W.Warehouse.Api.Application.Command.ReportlossesCommand;
using W.Warehouse.Repository.Interface;

namespace W.Warehouse.Api.Application.CommandHandlder.ReportlossesCommandHandler
{
    public class ReportlossEsexamineCommandHandler : IRequestHandler<ReportlossEsexamineCommand, int>
    {
        private readonly IReportlossesRepository _reportlossesRepository;

        public ReportlossEsexamineCommandHandler(IReportlossesRepository reportlossesRepository) { 
            _reportlossesRepository = reportlossesRepository;
        }
        /// <summary>
        /// 审核报损
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(ReportlossEsexamineCommand request, CancellationToken cancellationToken)
        {
            var list = await _reportlossesRepository.GetAllAsync();
            var plist=list.Where(x=>x.ReportlossesId==request.ReportlossesId).FirstOrDefault();
            if (plist != null) { 
                plist.ExaminePeople=request.ExaminePeople;
                plist.ExamineTime=DateTime.Now;
                plist.DocumentState=request.DocumentState;
            }
            return await _reportlossesRepository.UpdateAsync(plist);
        }
    }
}
